package com.mybase.app.fourBase;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.mybase.app.entity.MyMenuItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by happy_000 on 2014/11/21.
 * 四大组件 及系统自带常用功能
 */
public class FourHomeActivity extends ListActivity{


    private ListAdapter mAdapter;
    List<MyMenuItem> itemList=new ArrayList<MyMenuItem>(0);
    private List<String> list=new ArrayList<String>(0);

    public  List<MyMenuItem> getRootMenuItems() {
        List<MyMenuItem> list=new ArrayList<MyMenuItem>(0);
        MyMenuItem menuItem1 = new MyMenuItem();
        menuItem1.setName("Activity 启动返回");
        menuItem1.setActivity(FristActivity.class);
        list.add(menuItem1);
        //**********************************************************
        MyMenuItem menuItem2 = new MyMenuItem();
        menuItem2.setName("Bindservice  绑定服务");
        menuItem2.setActivity(BindServiceActivity.class);
        list.add(menuItem2);
        //**********************************************************
        MyMenuItem menuItem3 = new MyMenuItem();
        menuItem3.setName("Camera  拍照返回");
        menuItem3.setActivity(CameraActivity.class);
        list.add(menuItem3);
        //**********************************************************
        MyMenuItem menuItem4 = new MyMenuItem();
        menuItem4.setName("Notifaication 通知");
        menuItem4.setActivity(NotificationActivity.class);
        list.add(menuItem4);
        //**********************************************************
        MyMenuItem menuItem5 = new MyMenuItem();
        menuItem5.setName("broadcast 广播");
        menuItem5.setActivity(BroadCastActivity.class);
        list.add(menuItem5);
        //**********************************************************
        MyMenuItem menuItem6 = new MyMenuItem();
        menuItem6.setName("Provider|DB 分享|数据");
        menuItem6.setActivity(ProviderActivity.class);
        list.add(menuItem6);
        //**********************************************************
        return list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        itemList= getRootMenuItems();
        initdatas();
        mAdapter=new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,list);
        setListAdapter(mAdapter);
    }
    private  void initdatas(){
        for (MyMenuItem myMenuItem : itemList) {
            list.add(myMenuItem.getName());
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        MyMenuItem myMenuItem=itemList.get(position);
        Intent intent=new Intent(FourHomeActivity.this,myMenuItem.getActivity());
        startActivityForResult(intent,RESULT_OK);
    }
}
